package bll;

import java.util.ArrayList;

import domain.Resource;
import domain.Task;

public class BllResource implements ResourceView {

	@Override
	public void addResource(Resource myResource,
			ArrayList<Resource> myResourceList) {
		myResourceList.add(myResource);
		
	}

	@Override
	public void removeResource(Resource myResource,
			ArrayList<Resource> myResourceList) {
		myResourceList.remove(myResource);
		
	}

	@Override
	public void updateResource(int id, Resource myResource,
			ArrayList<Resource> myResourceList) {
		for(int i=0 ; i <= myResourceList.size(); i++)
		{
			if(myResourceList.get(i).getId() == id)
			{
				myResourceList.set(i, myResource);
			}
		}
		}
	
	@Override
	public void deleteResourceFromTask(int resourceId, Task myTask, ArrayList<Task> myTaskList){
		
	for(int i=0; i <= myTaskList.size(); i++)
	{
		if(myTaskList.get(i).getResourceId() == resourceId)
		{
			myTask.setResourceId(0);
			myTaskList.set(i, myTask);
		}
	}
	}
	}


